/*
 * [文 件 名]:B5MActivityHelper.java
 * [创 建 人]:allenwang
 * [创建时间]:Oct 30, 2013
 * [编　　码]:UTF-8
 * [版　　权]:Copyright © 2012 B5Msoft Co,Ltd. 
*/

package com.core.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.core.controller.B5MBaseFragment;
import com.cptravel.R;

/**
 *	[简要描述]:
 *	[详细描述]:
 *	@author	[allenwang]
 *	@email	[allen.wang@b5m.com]
 *	@version	[版本号,Oct 30, 2013]
 *	@see		[B5MActivityHelper]
 *	@package	[com.b5m.afw.internal]
 *	@since	[afw]
 */
public class B5MActivityHelper
{
    public static void showInputKeyboard(Context context , View view)
    {
        if (null != view)
        {
            InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
        }
        B5MDisplayHelper.init(context);
    }

    public static void hideInputKeyboard(Context context , View view)
    {
        if (null != view)
        {
            InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    /**
     * @param context
     * @param clazz
     */
    public static void startActivity(Activity activity , Class<?> clazz)
    {
        startActivity(activity, clazz, true);
    }

    /**
     * @param context
     * @param clazz
     * @param bundle
     */
    public static void startActivity(Activity activity , Class<?> clazz , Bundle bundle)
    {
        startActivity(activity, clazz, bundle, true);
    }

    /**
     * @param context
     * @param clazz
     * @param bundle
     */
    public static void startActivity(Activity activity , Class<?> clazz , boolean isAnimation)
    {
        Intent intent = new Intent();
        intent.setClass(activity, clazz);
        activity.startActivity(intent);
        if (isAnimation)
        {
            activity.overridePendingTransition(R.anim.activity_in_right, R.anim.activity_out_left);
        }
    }

    /**
     * @param context
     * @param clazz
     * @param bundle
     */
    public static void startActivity(Activity activity , Class<?> clazz , Bundle bundle , boolean isAnimation)
    {
        Intent intent = new Intent();
        intent.setClass(activity, clazz);
        if (bundle != null)
        {
            intent.putExtras(bundle);
        }
        activity.startActivity(intent);
        if (isAnimation)
        {
            activity.overridePendingTransition(R.anim.activity_in_right, R.anim.activity_out_left);
        }
    }

    /**
     * @param activity
     * @param clazz
     * @param bundle
     * @param resultCode
     */
    public static void startActivityForResult(Activity activity , Class<?> clazz , Bundle bundle , int requestCode)
    {
        Intent intent = new Intent();
        intent.setClass(activity, clazz);
        if (bundle != null)
        {
            intent.putExtras(bundle);
        }
        activity.startActivityForResult(intent, requestCode);
        activity.overridePendingTransition(R.anim.activity_in_right, R.anim.activity_out_left);
    }

    /**
     * @param activity
     * @param resultCode
     */
    public static void startActivityForResult(Activity activity , Class<?> clazz , int requestCode)
    {
        startActivityForResult(activity, clazz, null, requestCode);
    }

    public static void startActivityForResult(B5MBaseFragment fragment , Class<?> clazz , Bundle bundle , int requestCode)
    {
        Intent intent = new Intent();
        intent.setClass(fragment.getActivity(), clazz);
        if (bundle != null)
        {
            intent.putExtras(bundle);
        }
        fragment.startActivityForResult(intent, requestCode);
        fragment.getActivity().overridePendingTransition(R.anim.activity_in_right, R.anim.activity_out_left);
    }

    public static void startActivityForResult(B5MBaseFragment fragment , Class<?> clazz , int requestCode)
    {
        Intent intent = new Intent();
        intent.setClass(fragment.getActivity(), clazz);
        fragment.startActivityForResult(intent, requestCode);
        fragment.getActivity().overridePendingTransition(R.anim.activity_in_right, R.anim.activity_out_left);
    }
}
